package com.jeff.tianti.cms.service;

import com.jeff.tianti.cms.dao.CompanyDao;
import com.jeff.tianti.cms.dto.CompanyQueryDTO;
import com.jeff.tianti.cms.entity.Company;
import com.jeff.tianti.common.entity.PageModel;
import com.jeff.tianti.common.service.CommonService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author xujianfang
 * @desc CompanyService��
 * @date 2019-07-15
 */
@Service
public class CompanyService extends CommonService<Company, String> {

    @Autowired
    private CompanyDao companyDao;

    @Autowired
    public void setCompanyDao(CompanyDao companyDao) {
        super.setCommonDao(companyDao);
    }

    public PageModel<Company> queryCompanyPage(CompanyQueryDTO companyQueryDTO) {
        return this.companyDao.queryCompanyPage(companyQueryDTO);
    }

    public List<Company> queryCompanyList(CompanyQueryDTO companyQueryDTO) {
        return this.companyDao.queryCompanyList(companyQueryDTO);
    }

    public Company findComByUid(String uid) {
        CompanyQueryDTO dto = new CompanyQueryDTO();
        dto.setUid(uid);
        List<Company> companies = this.queryCompanyList(dto);
        if (CollectionUtils.isEmpty(companies)) {
            throw new RuntimeException("发布职位之前请先填写公司信息");
        }
        return companies.get(0);
    }

    public Page<Company> findAllNoDel(Pageable pageable) {
        return companyDao.findAllNoDel(pageable);
    }

    public Boolean findByUid(String uid) {
        List<Company> companys = companyDao.findByUidNoDel(uid);
        return CollectionUtils.isNotEmpty(companys);
    }

    public Company findByUidMes(String uid) {
        List<Company> list = companyDao.findByUid(uid);
        return list.get(0);
    }
}